package com.grm.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;

/**
 * desc: 后端返回json统一格式封装类
 *
 * @author gaorimao
 * @since 2021-3-13
 */
@Data
@ToString
@AllArgsConstructor
public class Result {
    private int code;
    private String message;
    private Object data;

    /**
     * desc: 成功，不返回数据
     *
     * @return result
     */
    public static Result success() {
        return new Result(200,"操作成功！",null);
    }

    /**
     * desc: 成功，返回数据
     *
     * @param data 数据
     * @return result
     */
    public static Result success(Object data) {
        return new Result(200,"操作成功！",data);
    }

    /**
     * desc: 失败
     *
     * @param code 错误码
     * @param message 错误详情
     * @return result
     */
    public static Result failed(Integer code,String message) {
        return new Result(code,message,null);
    }
}
